﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ESHOP.Domain;
using System.Data.Common;

namespace ESHOP.DAO
{
    public class QuocGiaDAO:BaseDAO
    {
       
        public QUOCGIA Get(String ma)
        {
            return _db.QUOCGIAs.Where(p => p.ID.Equals(ma)).SingleOrDefault();
        }

        public List<QUOCGIA> GetList()
        {
            return _db.QUOCGIAs.ToList();
        }
        public int Update(QUOCGIA objui)
        {
            try
            {
                var objdb = Get(objui.ID);
                if (objdb != null)
                {
                    objdb.TENQUOCGIA = objui.TENQUOCGIA;
                    _db.SubmitChanges();
                }
            }
            catch
            {
                return 0;
            }
            return 1;
        }

        public int Insert(QUOCGIA objui)
        {

            DbTransaction trans = null;
            try
            {
                _db.Connection.Open();
                trans = _db.Connection.BeginTransaction();
                _db.Transaction = trans;
                _db.QUOCGIAs.InsertOnSubmit(objui);
                _db.SubmitChanges();
                trans.Commit();
            }
            catch
            {
                return 0;
            }
            return 1;
        }

        public int Delete(String ma)
        {

            try
            {
                var objdb= Get(ma);
                if (objdb != null)
                {
                    _db.QUOCGIAs.DeleteOnSubmit(objdb);
                    _db.SubmitChanges();
                }
            }
            catch
            {
                return 0;
            }
            return 1;
        }


    }
}
